﻿using System;

using Engine;
using Engine.Result;

using Scheduler;

using Context = System.Runtime.Remoting.Contexts.Context;
using EventArgs = Scheduler.EventArgs;

namespace ServiceImp
{
    public class DeviceUnderTestHandler : Middleware
    {
        public event EventHandler<ChipResult> OnChipResult;
        public DeviceUnderTestHandler(EventHandler<ChipResult> onChipResult) : base()
        {
            OnChipResult = onChipResult;
        }

        public override bool Filter(Scheduler.Context ctx, EventArgs args)
        {
            return true;
        }

        protected override void DoHandleEvent(Scheduler.Context ctx, EventArgs args)
        {
            if (!(ctx is WaferTesterContext context))
                return;

            switch (args.Id)
            {
                case EventId.PassBegin:

                    break;
                case EventId.PassEnd:
                    var chipResult = context.Result.GetChipResultById(context.DUT);
                    //todo 格式转换问题
                    var value = (ValueTuple<int, int>)context.DUT;




                    OnChipResult?.Invoke(this, new ChipResult() { Chip = new DUTPoint(value.Item1, value.Item2)});

                    break;
                default:
                    break;
            }
        }
    }
}
